<script setup lang="ts">
import HeaderView from '../components/HeaderView.vue'
import FooterView from '../components/FooterView.vue'
</script>

<template>

  <HeaderView />

  <div class="container-container-my">

    <el-row :gutter="20">
      <el-col :span="4">
        <div class="my-left">
          <div class="face">
            <div class="facename">{{ userInfo.getUser().first }}</div>
            <h2>{{ userInfo.getUser().email }}</h2>
          </div>
          <div class="list">
            <router-link to="/Myhome" class="on">
              <svg t="1745294444222" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7560"><path d="M793.1 959.9H232.9C158.5 959.9 98 899.4 98 825V201.5c0-74.4 60.5-134.9 134.9-134.9H793c74.4 0 134.9 60.5 134.9 134.9V825c0.1 74.4-60.4 134.9-134.8 134.9z m-560.2-804c-25.1 0-45.6 20.5-45.6 45.6V825c0 25.1 20.5 45.6 45.6 45.6H793c25.1 0 45.6-20.5 45.6-45.6V201.5c0-25.1-20.5-45.6-45.6-45.6H232.9z" p-id="7561"></path><path d="M707.9 365.7H322.1c-24.7 0-44.7-20-44.7-44.7 0-24.7 20-44.7 44.7-44.7h385.7c24.7 0 44.7 20 44.7 44.7 0 24.7-20 44.7-44.6 44.7zM707.9 557.1H322.1c-24.7 0-44.7-20-44.7-44.7s20-44.7 44.7-44.7h385.7c24.7 0 44.7 20 44.7 44.7s-20 44.7-44.6 44.7zM573.3 748.5H322.1c-24.7 0-44.7-20-44.7-44.7 0-24.7 20-44.7 44.7-44.7h251.2c24.7 0 44.7 20 44.7 44.7 0 24.7-20 44.7-44.7 44.7z" p-id="7562"></path></svg>
              My Orders
            </router-link>

            <router-link to="/Settings">
              <svg t="1745294165954" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7098"><path d="M668.6 922.2H357.4c-48.1 0-92.9-26-116.7-67.8L84.2 579.7c-23.4-41-23.4-92 0-133L240.8 172c23.8-41.8 68.5-67.8 116.7-67.8h311.1c48.1 0 92.9 26 116.7 67.8l156.6 274.7c23.4 41 23.4 92 0 133L785.2 854.4c-23.8 41.8-68.5 67.8-116.6 67.8zM357.4 193.8c-16 0-30.9 8.6-38.9 22.6L162 491.1c-7.8 13.7-7.8 30.6 0 44.3l156.6 274.7c7.9 13.9 22.8 22.6 38.9 22.6h311.1c16 0 30.9-8.6 38.9-22.6L864 535.4c7.8-13.7 7.8-30.6 0-44.3L707.4 216.4c-7.9-13.9-22.8-22.6-38.9-22.6H357.4z"  p-id="7099"></path><path d="M513 696.4c-101 0-183.2-82.2-183.2-183.2S412 330.1 513 330.1s183.2 82.2 183.2 183.2S614 696.4 513 696.4z m0-276.8c-51.6 0-93.6 42-93.6 93.6s42 93.6 93.6 93.6 93.6-42 93.6-93.6-42-93.6-93.6-93.6z"  p-id="7100"></path></svg>
              Settings
            </router-link>
          </div>
        </div>
      </el-col>
      <el-col :span="20">
        <div class="my-right">
          <h2>My Orders</h2>

          <!-- 如果沒有订单 -->
          <div v-if="orders.length === 0" class="my-right-none">
              <el-empty  />
              <div class="none-right">
                <h4>As of now, no orders have been received!</h4>
                <router-link to="/">Just browsing</router-link>
              </div>
         </div>


        <!-- 如果有订单 -->
         <div v-if="orders.length > 0" class="my-right-orders">
            <router-link v-for="item in orders" :key="item.id" :to="'/Details/'+item.goods.id" target="_blank">
              <div class="my-right-orders-list">
                <div class="time">
                  <svg t="1745303637132" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9101" ><path d="M512.7 959.8c-247 0-448-201-448-448s201-448 448-448 448 201 448 448-200.9 448-448 448z m0-806.4c-197.6 0-358.4 160.8-358.4 358.4s160.8 358.4 358.4 358.4 358.4-160.8 358.4-358.4-160.7-358.4-358.4-358.4z" p-id="9102"></path><path d="M700 576.8H512.7c-24.6 0-44.6-19.9-44.8-44.5L466 254.5c-0.2-24.7 19.8-44.9 44.5-45.1h0.3c24.6 0 44.6 19.9 44.8 44.5l1.6 233.3H700c24.7 0 44.8 20.1 44.8 44.8 0 24.7-20.1 44.8-44.8 44.8z" p-id="9103"></path></svg>
                  {{ formattedDate(item.ctime*1000) }}
                </div>
                <div class="more">
                  <el-image :src="item.goods.pic" />
                  <div class="tips">
                    <div class="name">{{ item.goods_name }}</div>
                    <div class="number">Order Number: {{item.order_no}}</div>
                    <div class="number">Qty:{{item.goods_number}}</div>
                    <div class="prices">$ {{ item.money }} </div>

                    
                    

                  <div v-if="item.status==1" class="stateon">Order delivery</div>
                  <div v-if="item.status==0" class="state">Order in progress</div>

                  </div>
                </div>
              </div>
            </router-link>
          </div>


        </div>

      </el-col>
    </el-row>

  </div>

  <FooterView class="footer" />

</template>

<script lang="ts">
import createAxios from '../utils/axios'
import { useUserInfo } from '../stores/userInfo'

const userInfo = useUserInfo()

const formattedDate2 = ((value) => {
  const date = new Date(value);
  return date.toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
  });
});

// 时间戳（毫秒）转日期字符串
const formattedDate = ((timestamp)=>{
  const date = new Date(timestamp);

  // 获取年月日时分秒
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  const hour = String(date.getHours()).padStart(2, '0');
  const minute = String(date.getMinutes()).padStart(2, '0');
  const second = String(date.getSeconds()).padStart(2, '0');

  return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
})


export default {
  data() {
    return {
      pageTitle: 'My Orders - Personal Center',
      orders: [],
    };
  },
  created() {
    this.updateTitle();
    this.fetchOrders()
  },
  methods: {
    updateTitle() {
      document.title = this.pageTitle; // 或者根据需要动态设置标题
    },
    fetchOrders(){
      createAxios({
          url: '/frontend/profile/order',
          method: 'post',
        },
        {
            showSuccessMessage: false,
        })
        .then((res) => {
            console.log('订单列表请求结果', res)
            this.orders = res.data.list
        })
        .catch(() => {
        })
    }
  }

}
</script>

<style>
.container-container-my {
  max-width: 1520px;
  min-width: 1000px;
  padding: 0 5%;
  margin: 170px auto 0 auto;
  min-height: 500px;
  .my-left {
    min-width: 175px;
    padding: 10px;
    .face {
      text-align: center;
      .facename {
      background-color: #333333;
      color: #fff;
      width: 60px;
      height: 60px;
      border-radius: 100px;
      margin-right: 6px;
      line-height: 60px;
      text-align: center;
      font-size: 20px;
      font-weight: 500;
      margin: 0 auto 14px auto;
    }

      h2 {
        font-size: 12px;
        line-height: 1.2;
        width: 125px;
        margin: 4px 0 0 25px;

         overflow: hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
      }
    }
    .list {
      margin: 50px 10px;

      a {
        font-weight: 600;
        display:flex;
        padding: 14px 16px;
        margin-top: 6px;

      }
      svg {
        margin-right: 4px;
        width: 18px;
        height: 18px;
      }
      a , svg {
      color: #666; fill: #666;
      height: 20px;
      line-height: 20px;
      }
      a.on , a.on svg {
        color: #ed0467; fill: #ed0467;
      }
      a:hover , a:hover svg   {
      background-color: #f6f6f6;
      }

    }
  }
  .my-right {
    padding: 10px 0 50px 60px;
    border-left: 1px solid #f1f1f1;
    .my-right-none {
      padding: 50px 0 0 0;
      margin: auto;
      display: flex;
      .el-empty {
         padding: 0 !important;
         .el-empty__description  {
          display: none;
         }
      }

      .none-right {
        padding: 40px 0 0 30px;
        h4 {
        font-weight: 500;
        padding-bottom: 20px;
        }
        a {
          background-color: #f0f2f8;
          padding: 10px 20px;
        }
        a:hover {
          color: #000;
          background-color: #f1f1f1;
        }
      }
    }
    .my-right-orders {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      a {
        width: 48%;
      }
      .my-right-orders-list {
        margin: 20px 0;

        padding: 12px 20px 20px 20px;
        border: 1px solid #f1f1f1;
        -webkit-box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
        box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
        .time {
          padding: 0 0 10px 0;
          display: flex;
          font-size: 12px;
          svg {
            width: 15px;
            height: 15px;
            margin: 4px 4px 0 0;
            fill: #666;
          }
        }
        .el-image {
          overflow: initial;
          display: contents;
          width: 100px;
        }
        img {
          width: 100px;
          height: 105px;
        }
        .more {
          width: 100%;
          display: flex;
          justify-content: space-between;
          .tips {
            width: calc( 100% - 120px);
            .name {
              font-weight: 700;
              font-size: 15px;
              line-height: 24px;
              height: 48px;

              display: -webkit-box;             /* 必须设置，用于多行溢出 */
  -webkit-box-orient: vertical;     /* 设置盒子排列方向为垂直 */
  -webkit-line-clamp: 2;            /* 限制显示的行数，例如显示 3 行 */
  overflow: hidden;
            }
            .number {
              font-size: 12px;
              white-space: break-spaces;
            }
            .prices {
              background-image: linear-gradient(to right, #f41cb2, #f25511) !important;
              -webkit-background-clip: text !important;
              color: transparent !important;
              display:inline-block;
              font-size: 16px;
              font-weight: 600;
              width: 100%;
            }
            .state {
              display:inline-block;
              background-image: linear-gradient(to right, #f41cb2, #f25511);
              margin-top: 10px;
              padding:  4px 10px;
              font-size: 12px;
              text-align: center;
              color: #ffffff;
              border-radius: 2px;
              float: right;
            }
            .stateon {
              display:inline-block;
              margin-top: 10px;
              padding:  4px 10px;
              font-size: 12px;
              text-align: center;
              color: #bbbbbb;
              border-radius: 2px;
              float: right;
              background-color: #f0f2f8;
            }
          }
        }
      }
    }
  }
}

@media only screen and (max-width: 1000px) {
  .container-container-my {
    margin-top: 20px;
    max-width: 100%;
    min-width: 100%;
  }
  .el-col-4 {
    width: 100% !important;
    min-width: 100% !important;
  }
  .my-left {
    width: 100% !important;
    min-width: 100% !important;
    padding: 0 !important;;
    .face {
      display: none;
    }
    .list {
      padding: 70px 0 0 0 !important;
      margin: 0 !important;
      display: flex;
      justify-items: center;
      align-items: center;
      a {
        width: 50%;
        text-align: center;
      }
    }
  }
  .el-col-20 {
    width: 100% !important;
    min-width: 100% !important;
  }
  .my-right {
    padding: 0 !important;
    border-left: 0 !important;
    border-top: 2px solid #000;
    margin-top: 10px;
    h2 {
      display: none;
    }
    .my-right-orders {
      padding-bottom: 20px;
    }
    .my-right-orders a {
      width: 100% !important;
    }

    .my-right-none {
      display: block !important;
      .none-right {
        padding: 40px 0 0 0 !important;
        text-align: center;
      }
    }
  }
  .footer {
    display: none;
  }
}
</style>
